<?php
/*
 * Created on Feb 10, 2011
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

define("ENTER",chr(13).chr(10));	//--- enter

include_once("../configure/admin.config.inc.php");	//--> admin global var
include_once("db.inc.php");							//--> db global var
include_once("Common.php");							//--> Common
include_once("Xml.php");							//--> Xml
include_once("Strings.php");						//--> String utils

$oCommon 	= new Common();		//--> Common
$oXml 		= new Xml();							//--> Xml
$objStrings = new Strings();

$oXml->add('url', '', '', 'start');
		
$url = ENTER . 'http://www.123gohelmets.com';
$oXml->add('loc', '', $url, 'start');
$oXml->add('loc', '', '', 'end');

$oXml->add('url', '', '', 'end');

$sql = "SELECT p.id, pd.name FROM products p, products_description pd WHERE p.status in ('hot', 'normal') AND p.id = pd.productID AND pd.languageID = 1";

$allproducts 	= $oCommon->getAllData(DB_TAG_PUBLIC, $sql);

foreach($allproducts as $row){
	$arrImages = $oCommon->getHash(DB_TAG_PUBLIC, "SELECT u.id, u.extName FROM upload_files u, product_images p WHERE u.id = p.imageID AND p.productID = " . $row['id'] . ' AND u.type = 1 ORDER BY p.isMain');
	
	
	$oXml->add('url', '', '', 'start');
	
	$url = ENTER . 'http://www.123gohelmets.com/p/' . $row['id'] . '/' . $objStrings->getCharNum($row['name']) . '.html';
	$oXml->add('loc', '', $url, 'start');
	$oXml->add('loc', '', '', 'end');
	
	if(count($arrImages) > 0){
		
		foreach($arrImages as $imageid => $imageExt){
			//<image:loc>http://example.com/image.jpg</image:loc>
			$oXml->add('image:image', '', '', 'start');
			
			$imageURL = ENTER . "http://www.123gohelmets.com/img/0/0/$imageid/" . $objStrings->getCharNum($row['name']) . '.' . $imageExt;
			$oXml->add('image:loc', '', $imageURL, 'start');
			
			$oXml->add('image:loc', '', '', 'end');
			$oXml->add('image:image', '', '', 'end');
		}
		
	}
	
	$oXml->add('url', '', '', 'end');
}


$sql = "SELECT id, name FROM info_class WHERE parentid > 0";

$allproducts 	= $oCommon->getAllData(DB_TAG_PUBLIC, $sql);

foreach($allproducts as $row){
	$oXml->add('url', '', '', 'start');
	
	$url = ENTER . 'http://www.123gohelmets.com/c/' . $row['id'] . '/1/' . $objStrings->getCharNum($row['name']) . '.html';
	$oXml->add('loc', '', $url, 'start');
	$oXml->add('loc', '', '', 'end');
	
	$oXml->add('url', '', '', 'end');
}



$oXml->createXml('../../siteMapFiles/googleSiteMap.xml', 'urlset', ' xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"');


echo "Created file by Crontab"

?>
